﻿Imports BE.BE

Namespace DAL
    Public Class DAL_Telefono

        Shared Sub guardarTelefono(pTelefono As Telefono_BE)

            Try
                pTelefono.Id = Helper_DAL.ObtenerProximoId("telefono")
            Catch ex As Exception

            End Try

            Dim strcomm As String = "insert into telefono (id_telefono, numero, id_objeto, tipo_objeto) values " & _
                "(" & pTelefono.Id & "," & pTelefono.Numero & "," & pTelefono.IdObjeto & "," & pTelefono.TipoObjeto & ")"

            Try

                Helper_DAL.ExecuteNonQuery(strcomm)

            Catch ex As Exception
                Throw ex
            End Try

        End Sub

        Shared Sub borrarTelefono(pTelefono As Telefono_BE)

        End Sub

        Shared Function obtenerTelefonosXIdObjeto(pId As Integer, pTipoObjeto As Telefono_BE.EnumTipoObjeto) As List(Of Telefono_BE)
            Dim strcomm As String = "select id_telefono, numero, id_objeto, tipo_objeto from telefono where id_objeto = " & pId & " and tipo_objeto = " & pTipoObjeto
            Dim mDS As New DataSet
            Dim mLista As New List(Of Telefono_BE)

            Try
                mDS = Helper_DAL.ExecuteDataset(strcomm)

                If mDS.Tables(0).Rows.Count > 0 Then
                    For Each dr As DataRow In mDS.Tables(0).Rows
                        Dim mTelefono As New Telefono_BE

                        mTelefono.Id = dr.Item(0)
                        mTelefono.Numero = dr.Item(1)
                        mTelefono.IdObjeto = dr.Item(2)
                        mTelefono.TipoObjeto = dr.Item(3)

                        mLista.Add(mTelefono)
                    Next

                End If
                Return mLista

            Catch ex As Exception
                Throw ex
            End Try
        End Function

    End Class
End Namespace

